distinctUntilChangedBy() works a lot like distinctUntilChanged(), throwing
out equivalent items and only emitting the first of those equivalents. The
difference is that distinctUntilChangedBy() takes a "key selector" lambda expression
or other function type. This lambda expression is responsible for returning
the object that should be used (via == comparisons) to determine what items
are equivalent or not.
In this case, our flow is of a series of pairs, and the key selector lambda
returns the first() piece of the Pair — in this case, that is the
Int value. distinctUntilChangedBy() then ignores Pair objects with
duplicate Int values, so only the first of our three 1-based Pair
objects is emitted.
You can learn more about this in:
Tags: